package com.sg.service.biz.app.nb;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.baseinfo.BaseInfoDO;
import com.sg.common.baseinfo.BaseInfoHolder;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.biz.app.common.TargetTempDto;
import com.sg.dto.biz.app.req.ImplementAcceptTargetTempFieldsReqDto;
import com.sg.dto.biz.app.req.ImplementBizPublicFieldPushMemoryReqDto;
import com.sg.dto.biz.app.req.UnrepeatedTargetObjReqDto;
import com.sg.dto.biz.app.res.ImplementAcceptTargetTempFieldsRespDto;
import com.sg.dto.biz.app.res.ImplementBizPublicFieldPushMemoryRespDto;
import com.sg.dto.biz.app.res.UnrepeatedTargetObjRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbTargetTemp {
    /**
     * code:collectionRemoveExistingData
     * name:M3去重指标（特殊方法）
     * desc:undefined
     * gen by moon at 9/19/2022, 6:48:02 PM
     **/
    @Trace(operationName = "M3去重指标（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public UnrepeatedTargetObjRespDto unrepeatedTargetObj(UnrepeatedTargetObjReqDto reqDto) {
        UnrepeatedTargetObjRespDto retData = new UnrepeatedTargetObjRespDto();
        List<TargetTempDto> filteredList = new ArrayList<>();
        for (TargetTempDto one : reqDto.getTargetTempList()) {
            if (!reqDto.getTargetObjList().contains(one.getObjectiveTemplateId())) {
                filteredList.add(one);
            }
        }
        retData.setTargetTempList(filteredList);
        return retData;
    }

    /**
     * code:receptionService
     * name:M3指标模板类型（定量）
     * desc:undefined
     * gen by moon at 12/9/2022, 1:46:25 PM
     **/
    @Trace(operationName = "M3指标模板类型（定量）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementAcceptTargetTempFieldsRespDto implementAcceptTargetTempFields(ImplementAcceptTargetTempFieldsReqDto reqDto) {
        return BeanUtil.toBean(reqDto, ImplementAcceptTargetTempFieldsRespDto.class);
    }

    /**
     * code:publicFieldCache
     * name:M3业务应用公共字段推送内存
     * desc:undefined
     * gen by moon at 5/29/2023, 9:56:14 PM
     **/
    @Trace(operationName = "M3业务应用公共字段推送内存")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementBizPublicFieldPushMemoryRespDto implementBizPublicFieldPushMemory(ImplementBizPublicFieldPushMemoryReqDto reqDto) {
        BaseInfoDO domain = new BaseInfoDO();
        if (BaseInfoHolder.contextHolder.get() != null) {
            BeanUtil.copyProperties(BaseInfoHolder.contextHolder.get().getBaseInfo(), domain);
            BaseInfoHolder.contextHolder.remove();
        }
        if (reqDto.getSpaceId() != null) {
            domain.setSpecSpaceId(reqDto.getSpaceId());
        }

        if (reqDto.getCreateInductionId() != null) {
            domain.setSpecInductionRecordId(reqDto.getCreateInductionId());
        }

        if (reqDto.getAppId() != null) {
            domain.setSpecAppId(reqDto.getAppId());
        }

        CommonFunctionHelper.setBaseInfoToLocal(domain);
        return new ImplementBizPublicFieldPushMemoryRespDto();
    }
    //手工接入方法
}
